package com.soap.desensitize.posterity.string;

import com.soap.desensitize.encry.IDesensitization;
import com.soap.desensitize.exception.strategy.DecodeException;
import com.soap.desensitize.exception.strategy.EncodeException;
import com.soap.desensitize.posterity.AbstractPosterity;
import com.soap.desensitize.strategy.rreversible.symmetry.DesStrategy;

/**
 * @desc	字符串加密解密
 * @author 	Administrator
 * @time	2022-04-21
 */
public class StringDesensitization extends AbstractPosterity<String> {
    /**
     * 默认使用des对称加密
     */
    private StringDesensitization(){
        super(DesStrategy.getInstance());
    }

    private static StringDesensitization instance = null;
    /**
     * @desc 获得实例
     * @return
     */
    public static synchronized StringDesensitization getInstance(){
        if(instance == null){
            instance = new StringDesensitization();
        }
        return instance;
    }

    /**
     * @desc 有参构造器
     * @param encry
     */
    public StringDesensitization(IDesensitization encry) {
        super(encry);
    }

    @Override
    public String encode(String data) throws EncodeException {
        return (String)encry.encode(data);
    }

    @Override
    public String decode(String data) throws DecodeException {
        return (String)encry.decode(data);
    }
}
